# coding: UTF-8
import os

def Create_Indexing_Interface(parameters, curdir, form, user_info=None):
	files = os.listdir(curdir)
	keyfile = ""
	for f in files:
		if os.path.splitext(f)[1] == ".key":
			keyfile = f
			break
	
	keylist = []
	
	if keyfile:
		for key in open("%s/%s" % (curdir, keyfile), "r"):
			if key.strip() != "":
				keylist.append(key)
			
	t = """
	<script type='text/javascript' src='/js/jquery.min.js'></script>
	<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js'></script>
	<script type='text/javascript' src='/js/indexing.js'></script>
	<div id="indexing">
	<input type="text" id="psh_search" size="20" autocomplete="off"/><span id="alreadyMsg" style="color:red; font-size:large;"></span><br />
	<div id="psh_search_title">PSH Search</div>
	<h1>Přiřazená hesla</h1>
	<ul id="suggestedSubjects">"""
	for k in keylist:
		t += """<li class="subject"><span class="subjectValue test" onClick='getDocBySubject(this)'>%s</span> <span class="removeSuggested" onClick='remove(this)'>×</span></li>\n""" % (k.strip()) 
	
	
	t += """</ul>
	<hr/>
	<div id="documentExamples">Dokumenty označené heslem '<span id="subject"></span>' (celkem <span id="recLen">0</span> dokumentu):</div>
	<div id="docs"></div>
	<select style="display:none;" id="selectedSubjects" name="selectedSubjects" multiple>
	</select>
	<input type='button' name='ENDE' value="Finish" onClick="document.forms[0].step.value='2';copySubjects();document.forms[0].submit();" /><br />
	</div>
	"""
	return t
	
if __name__ == "__main__":
	w = open("/opt/cds-invenio/var/www/img/CII.html", "w")
	w.write("""<!DOCTYPE html>
<html>
	<head>
		<title>CII test</title>
		<meta charset="UTF-8">
		<link type="text/css" rel="stylesheet" href="/img/jquery.ui.autocomplete.css" />
	</head>
	<body><form>""")
	w.write(Create_Indexing_Interface("", "/opt/cds-invenio/var/data/submit/storage/running/test/1294743658_2383/", ""))
	w.write("""</form></body></html>""")
